package org.cqipc.edu.utils;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Description: 公共方法
 * @ClassNmae: CommonUtils
 * @Author: HeYue
 * @DateTime: 2020-11-01 04:17
 **/
public class CommonUtils {

    /**
     * @Description: 将前端传过来的id字符串封装成Integer集合并返回(批量操作)
     * @Author: HeYue
     * @DateTime: 2020/11/1 4:17
     **/
    public static List<Integer> StringToIntegerlIST(String ids, String term) {
        String idString[] = ids.trim().split(term);
        List<Integer> list = new ArrayList<>();
        for (String id : idString) {
            list.add(Integer.parseInt(id));
        }
        return list;
    }


    /**
     * @Description: 生成range范围内的num个随机数
     * @Author: HeYue
     * @DateTime: 2020/11/1 4:17
     **/
    public static Set<Integer> randomNum(Integer num, Integer range) {
        Integer n = 0;
        Random random = new Random();
        Set<Integer> set = new HashSet<Integer>();
        while (n < num) {
            int temp = random.nextInt(range);
            set.add(temp);
            n = set.size();
        }
        return set;
    }

    /**
     * @Description: 获取当前日期时间
     * @Author: HeYue
     * @DateTime: 2020/11/1 4:19
     **/
    public static String getCurrenDateTime() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }

    /**
     * @Description: 获取当前时间
     * @Author: HeYue
     * @DateTime: 2020/11/1 4:20
     **/
    public static String getCurrenTime() {
        return new SimpleDateFormat("HH:mm:ss").format(new Date());
    }

    /**
     * @Description: 获取当前日期
     * @Author: HeYue
     * @DateTime: 2020/11/1 4:20
     **/
    public static String getCurrenDate() {
        return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    }
}
